﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using UtilPublic.Mysql;
using ServerBase.Other;
using System.Text;
using UtilLib;
using ServerBase.Protocol;
using ServerBase.Service;
using System;
using ServerBase.Config;
using System.Collections.Generic;

namespace ServerPublic.Manager
{
    /// <summary>
    /// 游戏记录系统
    /// </summary>
    public static class RecordMgr
    {
        /// <summary>
        /// 添加记录
        /// </summary>
        /// <param name="RecType"></param>
        /// <param name="ActionSource"></param>
        /// <param name="puid"></param>
        /// <param name="args"></param>
        public static void Rec(this (ERecordType RecType, EActionSource ActionSource) typesource, long puid = 0, params object[] args)
        {
            MysqlRecord.MysqlRec(typesource.RecType.ToString(), typesource.ActionSource.ToString(), puid, args);
        }
        /// <summary>
        /// 添加记录
        /// </summary>
        /// <param name="RecType"></param>
        /// <param name="ActionSource"></param>
        /// <param name="puid"></param>
        /// <param name="v0"></param>
        /// <param name="args"></param>
        public static void RecValue(this (ERecordType RecType, EActionSource ActionSource) typesource, long puid = 0, long v0 = 0, params object[] args)
        {
            MysqlRecord.MysqlRecValue(typesource.RecType.ToString(), typesource.ActionSource.ToString(), puid, v0, args);
        }
        /// <summary>
        /// 添加记录
        /// </summary>
        /// <param name="RecType"></param>
        /// <param name="ActionSource"></param>
        /// <param name="puid"></param>
        /// <param name="dt"></param>
        /// <param name="args"></param>
        public static void RecData(this (ERecordType RecType, EActionSource ActionSource) typesource, long puid, DateTime dt, params object[] args)
        {
            MysqlRecord.MysqlRecData(typesource.RecType.ToString(), typesource.ActionSource.ToString(), puid, dt, args);
        }
        public static DictList<EServerType, ERecordType> DictListRecCreateMysqlTable = new DictList<EServerType, ERecordType>()
        {
            { 
                EServerType.充值, new List<ERecordType>()            
                {
                    ERecordType.HTTP消息收到,
                    //ERecordType.支付消息收到,
                    //ERecordType.支付消息添加,
                } 
            },
            {
                EServerType.登录, new List<ERecordType>()
                {
                    ERecordType.HTTP消息收到,
                    ERecordType.注册账号,
                }
            },
            {
                EServerType.战斗, new List<ERecordType>()
                {
                    ERecordType.HTTP消息收到,
                }
            },
        };
        /// <summary>
        /// 创建表
        /// </summary>
        public static void RecCreateMysqlTable()
        {
            foreach (var item in Enum.GetValues(typeof(ERecordType)))
            {
                var recordtype = (ERecordType)item;
                if (BaseServerInfo.ServerType != EServerType.游戏)
                {
                    if (!DictListRecCreateMysqlTable.TryGetValue(BaseServerInfo.ServerType, out var list))
                    {
                        continue;
                    }
                    if (!list.Contains(recordtype))
                    {
                        continue;
                    }
                }
                MysqlRecord.MysqlCreateTableGameRecord(recordtype.ToString(), (recordtype == ERecordType.登录游戏));
            }
        }
    }


}